package org.wanho.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2023-04-21 10:44
 * Description：<描述>
 */
@WebServlet(urlPatterns = "/live", loadOnStartup = 1, initParams = {
        @WebInitParam(name = "name", value = "admin"),
        @WebInitParam(name = "age", value = "22")
})
public class LiveServlet extends HttpServlet {

    public LiveServlet(){
        System.out.println("LiveServlet实例化。。。。。。。");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("LiveServlet正在初始化。。。。。");

        String name = getInitParameter("name");
        int age = Integer.parseInt(getInitParameter("age"));
        System.out.println("初始化参数："+name+","+age);

        // ServletContext servletContext = getServletContext();
        // String sex = servletContext.getInitParameter("sex");
        String sex = getServletContext().getInitParameter("sex");
        System.out.println("上下文参数："+sex);
    }

    // @Override
    // protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //     System.out.println("LiveServlet正在提供服务。。。。。。。。");
    // }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行doGet。。。。。。。。。。。。。。。。");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行doPost。。。。。。。。。。。。。。。。");
    }

    @Override
    public void destroy() {
        System.out.println("LiveServlet即将被销毁。。。。。。。。");
    }
}
